package top.xiangqifu.springboot2.user.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import top.xiangqifu.springboot2.user.base.BaseDataResult;
import top.xiangqifu.springboot2.user.base.BasePageResult;
import top.xiangqifu.springboot2.user.base.PageBean;
import top.xiangqifu.springboot2.user.entity.TbFile;
import top.xiangqifu.springboot2.user.service.FileService;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


@RestController
@RequestMapping("/file")
@RequiredArgsConstructor
@Api(tags = "文件上传相关接口")
public class FileController {
    private final FileService fileService;

    @ApiOperation(value ="文件上传",notes = "文件上传功能接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "info",value = "文件描述",dataTypeClass = String.class ,required = true),
    })
    @PostMapping
    public BaseDataResult<TbFile> upload(TbFile tbFile, MultipartFile file){
        return fileService.upload(tbFile,file);
    }

    @ApiOperation(value ="文件下载",notes = "文件下载功能接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "fid",value = "文件id",dataTypeClass = String.class ,required = true),
    })
    @GetMapping("/{id}")
    public void download(@PathVariable("id") Integer id, HttpServletResponse response){
        fileService.download(id,response);
    }

    @ApiOperation(value ="用户历史图片",notes = "获取用户历史图片功能接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNumber",value = "分页页码",dataTypeClass = String.class ,required = true),
            @ApiImplicitParam(name = "pageSize",value = "分页大小",dataTypeClass = String.class ,required = true),
    })
    @GetMapping
    public BasePageResult<List<TbFile>> historyFiles(PageBean pageBean){
        return fileService.historyFile(pageBean);
    }

}
